<?php
class OneOfTwoValidatorSchema extends sfValidatorSchema
{
  const OPTION_WIDGET_A = 'widget_a';
  const OPTION_WIDGET_B = 'widget_b';

  protected function configure ($options = array(), $messages = array())
  {
    $this->addOption(self::OPTION_WIDGET_A, array());
    $this->addOption(self::OPTION_WIDGET_B, array());
  }

  protected function doClean ($values)
  {
    if (! $values[$this->getOption(self::OPTION_WIDGET_A)] && ! $values[$this->getOption(self::OPTION_WIDGET_B)])
    {
      
      $errorSchema = new sfValidatorErrorSchema($this);
      $errorSchema->addError(new sfValidatorError($this, 'invalid'), 'invalid');
      throw $errorSchema;
    }
    
    return $values;
  }
}